package com.dzk.cp.c11x5.index.rx.yl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.dzk.cp.c11x5.index.BaseC11x5Index;
import com.dzk.cp.c11x5.pojo.R5;
import com.dzk.cp.c11x5.util.C11x5Utils;
import com.dzk.cp.c11x5.util.SpringBeanUtils;

public abstract class RXnYLIndex extends BaseC11x5Index {
	
	private String rxc;
	
	public RXnYLIndex setParams(int code, int num, int unit, String rxc) {
		super.setParams(code, num, unit);
		this.rxc = rxc;
		return this;
	}
	
	@Override
	public Map<Integer, Integer> index() {
		Map<Integer, Integer> resultMap = new LinkedHashMap<Integer, Integer>();
		int n = getLastestNum();
		List<? extends R5> r5s = SpringBeanUtils.getR5Service(code).queryLatest(n);
		String[] rxArr = rxc.split(" ");
		int i = -1, j = 0, k = 0;
		for (; k < n; k++) {
			R5 r5 = r5s.get(k);
			if (C11x5Utils.contain(r5.getNs().split(" "), rxArr)) {
				resultMap.put(++j, k - i - 1);
				i = k;
			}
		}
		resultMap.put(++j, k - 1 - i);
		return resultMap;
	}
	
	public static RXnYLIndex getInstance(int code, int num, int unit, String rxc) {
		int n = (rxc.length() + 1 ) / 3;
		switch (n) {
		case 1:
			return new RX1YLIndex().setParams(code, num, unit, rxc);
		case 2:
			return new RX2YLIndex().setParams(code, num, unit, rxc);
		case 3:
			return new RX3YLIndex().setParams(code, num, unit, rxc);
		case 4:
			return new RX4YLIndex().setParams(code, num, unit, rxc);
		case 5:
			return new RX5YLIndex().setParams(code, num, unit, rxc);
		case 6:
			return new RX6YLIndex().setParams(code, num, unit, rxc);
		case 7:
			return new RX7YLIndex().setParams(code, num, unit, rxc);
		case 8:
			return new RX8YLIndex().setParams(code, num, unit, rxc);
		case 9:
			return new RX9YLIndex().setParams(code, num, unit, rxc);
		default:
			return null;
		}
	}

}

class RX1YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 11 / 5;
	}

}

class RX2YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 55 / 10;
	}

}

class RX3YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 165 / 10;
	}

}

class RX4YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 66;
	}

}

class RX5YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 462;
	}

}

class RX6YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 78;
	}

}

class RX7YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 22;
	}

}

class RX8YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 33 / 4;
	}

}

class RX9YLIndex extends RXnYLIndex {

	@Override
	protected int getZQ() {
		return 11 / 3;
	}

}
